﻿﻿using System;
using System.IO;
using System.Text;
using System.Web;

namespace SyCODE.Blog
{
    /// <summary>
    /// Class1 的摘要说明。
    /// </summary>
    public class ScriptErrorLog : IHttpHandler
    {
        public bool IsReusable
        {
            get
            {
                return true;
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            string dir = AppPath.FromRelativePath("logfiles\\script\\");

            if (!Directory.Exists(dir))
                Directory.CreateDirectory(dir);

            FileStream fs = new FileStream(dir + String.Format("{0}.log", DateTime.Now.ToString("yyyyMMdd")), FileMode.Create | FileMode.Append, FileAccess.Write, FileShare.Write);
            try
            {
                fs.Write(context.Request.BinaryRead(context.Request.TotalBytes), 0, context.Request.TotalBytes);
            }
            finally
            {
                fs.Close();
            }
        }
    }
}